from django.shortcuts import redirect
from django.utils.deprecation import MiddlewareMixin


class AuthMiddleware(MiddlewareMixin):
    """ 中间件 """

    def process_request(self, request):

        # 排除不需要登录就能访问的页面
        #  request.path_info 获取当前用户请求的url

        if request.path_info == '/login/':
            return
        info_dict = request.session.get('info')
        if info_dict:
            return

        return redirect('/login/')
